package com.liutaw.nanjingair.views.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.liutaw.nanjingair.R;
import com.liutaw.nanjingair.utils.FileUtils;
import com.szjlxh.domain.model.index.WeatherHourData;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by liutao on 16/2/18.
 */
public class WeatherHourInfoAdapter extends RecyclerView.Adapter<WeatherHourInfoAdapter.ViewHolder> {

    private Context context;
    private List<WeatherHourData> data;

    public WeatherHourInfoAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
//        initData();
    }
//
//    private void initData() {
//        WeatherHourInfo info = new WeatherHourInfo();
//        info.hour = "X时";
//        info.state = 1;
//        info.desc = "多云";
//        info.degree = "12°";
//        info.wind = "东风";
//        info.windLevel = "3级";
//        info.rain = "0mm";
//        for (int i = 1; i <= 24; i++) {
//            weatherHourInfoList.add(info);
//        }
//    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        View view = LayoutInflater.from(this.context).inflate(R.layout.item_weather_info_hour, parent, false);
        view.getLayoutParams().width = windowManager.getDefaultDisplay().getWidth() / 6;
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        WeatherHourData content = data.get(position);
        holder.textHour.setText(content.getHour());
        holder.imgState.setImageResource(FileUtils.getResId(context,content.getWeatherResString()));
        holder.textDesc.setText(content.getWeatherName());
        holder.textDegree.setText(content.getTemp());
        holder.textWind.setText(content.getWindName());
        holder.textWindLevel.setText(content.getWindScale());
        holder.textRain.setText(content.getRainAmount());

    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    public List<WeatherHourData> getData() {
        return data;
    }

    public void setData(List<WeatherHourData> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.text_hour)
        TextView textHour;
        @Bind(R.id.img_state)
        ImageView imgState;
        @Bind(R.id.text_desc)
        TextView textDesc;
        @Bind(R.id.text_degree)
        TextView textDegree;
        @Bind(R.id.text_wind)
        TextView textWind;
        @Bind(R.id.text_wind_level)
        TextView textWindLevel;
        @Bind(R.id.text_rain)
        TextView textRain;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
